﻿// ===============================================================================
// WebsiteRuleTest.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Rules.Tests
{
    using EOS.Framework.Rules;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for RegexRuleTest and is intended
    /// to contain all RegexRuleTest Unit Tests
    /// </summary>
    [TestClass()]
    public class WebsiteRuleTest
    {
        private TestContext testContextInstance;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        /// A test for Validate method.
        /// </summary>
        [TestMethod()]
        public void WebsiteRuleValidateTest()
        {
            Rule rule = new WebsiteRule("Test");
            bool result = false;

            result = rule.Validate("http://www.eos.de");
            Assert.IsTrue(result, "Url not accepted.");

            result = rule.Validate("http://sub.eos.de");
            Assert.IsTrue(result, "Url with subdomain not accepted.");

            result = rule.Validate("http://sub.eos.de/part/part/");
            Assert.IsTrue(result, "REST-Like Url not accepted.");

            result = rule.Validate("http://sub.eos.de?id=123#m");
            Assert.IsTrue(result, "Url with parameter not accepted.");

            result = rule.Validate("http://sub.eos.de/index.html");
            Assert.IsTrue(result, "Url with file extension not accepted.");

            result = rule.Validate("www.google.de");
            Assert.IsFalse(result, "URL without protocoll was accepted.");
        }

        /// <summary>
        /// A test for Validate method.
        /// </summary>
        [TestMethod()]
        public void WebsiteRuleValidateEmptyTest()
        {
            Rule rule = new WebsiteRule("Test", true);
            bool result = false;

            result = rule.Validate(string.Empty);
            Assert.IsTrue(result, "Empty object not accepted.");
        }
    }
}
